﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// Definition of a URL property which needs to resolve its value using a method like ResolveUrl.
	/// </summary>
	public class UrlPropertyDefinition : PropertyDefinition<string>
	{
		/// <summary>
		/// Ctor.
		/// </summary>
		/// <param name="name"></param>
		/// <param name="shortName"></param>
		/// <param name="defaultValue"></param>
		public UrlPropertyDefinition(string name, string shortName, string defaultValue)
			: base(name, shortName, defaultValue)
		{
		}
		/// <summary>
		/// Serializes the value of this property for the specified control to the specified <see cref="JsonWriter"/>.
		/// </summary>
		/// <param name="control"></param>
		/// <param name="jw"></param>
		protected override void DoSerializeValue(TControl control, TA.JSON.JsonWriter jw)
		{
			if (string.IsNullOrEmpty(this.GetValue(control)))
				jw.Value("");
			else
				jw.Value(control.ResolveUrl(this.GetValue(control)));
		}
	}
}
